/////////////////////////////////////////////////////////////////////////
// File:        SettingsDlg.h
// Purpose:     A frame which is used to change the TNod settings in the 
//              registry.
// Author:      Tukero
// Modified by: 
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
/////////////////////////////////////////////////////////////////////////

#ifndef _TNOD_SETTINGSDLG_
#define _TNOD_SETTINGSDLG_

#ifndef WX_PRECOMP
#  include <wx/wx.h>
#else
#  include <wx/wxprec.h>
#endif

#include <wx/statline.h>
#include <wx/treectrl.h>
#include <wx/spinctrl.h>
#include <wx/treebook.h>
#include <wx/sizer.h>
#include "MultiLanguage.h"
#include "wx/proxysettingsdlg.h"
#include "PassServers.h"

////Dialog Style Start
#undef SETTINGDLG_STYLE
#define SETTINGDLG_STYLE wxCAPTION | wxSYSTEM_MENU | wxMINIMIZE_BOX | wxCLOSE_BOX
////Dialog Style End
WX_DEFINE_ARRAY_INT(int, ArrayInt);

class SettingsDlg : public wxFrame
{
	private:
		DECLARE_EVENT_TABLE();
        //Multilanguage   Lang;
		
	public:
		SettingsDlg(wxWindow *parent = NULL, wxWindowID id = 1, const wxString &title = wxT("TNod"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = SETTINGDLG_STYLE);
		virtual ~SettingsDlg();

        void OnOptNewVersion(wxCommandEvent& event);
    	void OnChkNewVersions(wxCommandEvent& event);
        void OnChkStartup(wxCommandEvent& event);
    	void OnBtnCancel(wxCommandEvent& event);
    	void OnBtnOk(wxCommandEvent& event);
    	void OnBtnConfigProxy(wxCommandEvent& event);
    	void OnOptProxy(wxCommandEvent& event);
    	void OnChkTrialLicense(wxCommandEvent& event);
    	void OnChkInsertIfExpire(wxCommandEvent& event);
        void OnChkAutoUpdate(wxCommandEvent& event);
    	void OnOptLicense(wxCommandEvent& event);
        void OnChkPassUnlock(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnInsertLicense(wxCommandEvent& event);
        void OnCheck4NewVersions(wxCommandEvent& event);
        void OnMenuClose(wxCommandEvent& event);
        void OnOficialServerMenu(wxTreeEvent& event);
        void OnPersonalServerMenu(wxTreeEvent& event);
        void OnItemVisitSite(wxCommandEvent& event);
        void OnItemCopy2Clipboard(wxCommandEvent& event);
        void OnTreeKeyDown(wxTreeEvent& event);

        void OnItemModify(wxCommandEvent& event);
        void OnItemDelete(wxCommandEvent& event);
        void OnItemMoveUp(wxCommandEvent& event);
        void OnItemMoveDown(wxCommandEvent& event);
        void OnItemAddServerAtFirst(wxCommandEvent& event);
        void OnItemAddServerAtLast(wxCommandEvent& event);
        void OnItemAddBeforeSel(wxCommandEvent& event);
        void OnItemAddAfterSel(wxCommandEvent& event);
        void OnBeginLabelEdit(wxTreeEvent& event);
        void OnEndLabelEdit(wxTreeEvent& event);
        void OnItemAddUserTag(wxCommandEvent& event);
        void OnItemAddPassTag(wxCommandEvent& event);

        void OnBtnAddServer(wxCommandEvent& event);
        void OnBtnModifyServer(wxCommandEvent& event);
        void OnBtnDeleteServer(wxCommandEvent& event);
        void OnBtnUpServer(wxCommandEvent& event);
        void OnBtnDownServer(wxCommandEvent& event);

	private:
		//Do not add custom control declarations between
		//GUI Control Declaration Start and GUI Control Declaration End.
		//wxDev-C++ will remove them. Add custom code after the block.
		////GUI Control Declaration Start
		wxSpinCtrl *m_spinSecs;
		wxStaticText *m_lblSecsWait4Internet;

		wxRadioButton *m_optUseTooltips;
		wxRadioButton *m_optUseDlg;
		wxStaticBox *m_boxNotifications;
		wxCheckBox *m_chkCheckNewVersions;
		wxMenuBar *m_menuBar;
		wxButton *m_btnCancel;
		wxButton *m_btnOk;
		wxBoxSizer *m_szInferior;
		wxStaticLine *m_linSeparator;
		wxStaticText *m_lblOfServersVersion;
		wxTextCtrl *m_edtServersVersion;
		wxTreeCtrl *m_treeOficialServers;
		wxPanel *m_nbOficialServers;
		wxButton *m_btnConfigProxy;
		wxRadioButton *m_optManualConfig;
		wxRadioButton *m_optNoProxy;
		wxRadioButton *m_optUseSameAsIE;
		wxPanel *m_nbProxy;
		wxPanel *m_nbNewVersion;
        
        wxPanel *m_nbPersonalServers;
        wxTreeCtrl *m_treePersonalServers;
        wxBitmapButton *m_bmbAddServer;
        wxBitmapButton *m_bmbModifyServer;
        wxBitmapButton *m_bmbDeleteServer;
        wxBitmapButton *m_bmbUp;
        wxBitmapButton *m_bmbDown;

		wxCheckBox *m_chkTrialLicenses;
		wxCheckBox *m_chkInsertIfExpire;
		wxRadioButton *m_optNoInsertIfValid;
		wxRadioButton *m_optInsertFirst;
		wxRadioButton *m_optInsertDiferent;
        wxCheckBox *m_chkAvoidNearExpiration;
		wxPanel *m_nbLicense;

		wxCheckBox *m_chkStartup;
		wxCheckBox *m_chkHiddenMode;
		wxCheckBox *m_chkPassUnlock;
        wxStaticText *m_lblLanguage;
        wxComboBox *m_cboLanguage;
		wxPanel *m_nbGeneral;
		wxTreebook *m_treeOptions;
		wxPanel *m_panel4Tree;
		wxBoxSizer *m_szGlobalSizer;
		wxPanel *m_panel;

		wxRadioButton *m_optPersonalOficial;
		wxRadioButton *m_optOficialPersonal;
		wxStaticBox *m_boxLoadOrder;
		wxTextCtrl *m_edtServer2CheckLicense;
		wxCheckBox *m_chkAutoUpdate;
		wxStaticBox *m_boxServer2CheckLicense;
        wxStaticText *m_lblCheck2;
		wxSpinCtrl *m_spinLic2CheckInEveryServer;
		wxStaticText *m_lblLicensesInEveryServer;

		wxPanel *m_nbCheckingLicense;
		
		wxBoxSizer *m_sizerServerOptions;
		wxBoxSizer *m_sizerPersonalServers;
		wxBoxSizer *m_sizerServersVersion;
		wxBoxSizer *m_sizerOficialServers;

        wxPanel *m_nbServers;

		wxStaticText    *m_lblLicensesAtTheTime;
		wxSpinCtrl      *m_spinLicenses2Check;
		wxStaticText    *m_lblCheck;

        wxProxySettings m_proxySettings;

        ArrayInt        m_languageCodes;

        wxThread        *m_threadRunning;

        bool             m_StartupCheckChanged;
        
        void LoadServers2Tree(LinkListServer *serverList, wxTreeCtrl *treeControl);

        void LoadSettings2Controls();

		void CheckControls(int section = -1);

        wxTreeItemId GetServerItemId(wxTreeCtrl *treeCtrl, wxTreeItemId& itemId);
        wxTreeItemId GetTagLabelId(wxTreeItemId& serverItemId, int tagType);
        wxTreeItemId AddTagLabel(wxTreeCtrl* treeCtrl, wxTreeItemId& serverItemId, int labelType);
        wxTreeItemId AddTagItem(wxTreeCtrl* treeCtrl, wxTreeItemId& tagLabelItem, int tagType, const wxString& itemText = wxT("new tag"));
        void CopyItemsRecursively(wxTreeCtrl& treeCtrl,const wxTreeItemId& idParent, wxTreeItemIdValue cookie, const wxTreeItemId& idParentOfCopy);
        void CopyItemSettings(wxTreeCtrl& treeCtrl, wxTreeItemId& destiny,wxTreeItemId& origin);
        void InterchangePositions(wxTreeCtrl& treeCtrl, wxTreeItemId& upperItem,wxTreeItemId& lowerItem);
        wxTreeItemId AddNewServer2Tree(wxTreeCtrl *treeCtrl, wxTreeItemId* afterItem, int pos, const wxString& itemText = wxT("http://new_url"));
        void AddAndEditNewTagItem(wxTreeCtrl* treeCtrl, wxTreeItemId& itemForReference, int labelItemType, int tagItemType);
        wxTreeItemId m_itemForMenu;

        void SavePersonalServers();
        void SaveItemsRecursively(wxTreeCtrl* treeCtrl, const wxTreeItemId& idParent, wxTreeItemIdValue cookie);

        void CreateServerList(wxTreeCtrl* treeCtrl, const wxTreeItemId& idParent,
                                     wxTreeItemIdValue cookie, LinkListServer* serverList, PassServer* server);
		
	private:
        wxString    m_tempPass4Unlock;
        int         m_RunsWithoutUpdate;
		enum
		{
			////GUI Enum Control ID Start

			ID_M_OPTUSETOOLTIPS = 1090,
			ID_M_OPTUSEDLG,
			ID_M_BOXNOTIFICATIONS,
			ID_M_CHKCHECKNEWVERSIONS,
			ID_MNU_ACTIONS,
			ID_MNU_INSERTLICENSE,
			ID_MNU_CHECKVERSION,
			ID_MNU_EXIT,
			ID_MNU_HELP,
			ID_MNU_ABOUT,

            ID_M_SPINSECS,
			ID_M_LBLSECSWAIT4INTERNET,
			
			ID_M_BTNCANCEL,
			ID_M_BTNOK,
			ID_M_LINSEPARATOR,
			ID_M_LBLOFSERVERSVERSION,
			ID_M_EDTSERVERSVERSION,
			ID_M_TREEOFICIALSERVERS,
			ID_M_NBOFICIALSERVERS,
            
            ID_M_NBPERSONALSERVERS,
            ID_M_TREEPERSONALSERVERS,
            ID_M_BMBADDSERVER,
            ID_M_BMBMODIFYSERVER,
            ID_M_BMBDELETESERVER,
            ID_M_BMBUP,
            ID_M_BMBDOWN,

			ID_M_BTNCONFIGPROXY,
			ID_M_OPTMANUALCONFIG,
			ID_M_OPTNOPROXY,
			ID_M_OPTUSESAMEASIE,
			ID_M_NBPROXY,
			ID_M_NBNEWVERSION,
			ID_M_CHKTRIALLICENSES,
			ID_M_CHKINSERTIFEXPIRE,
			ID_M_OPTNOINSERTIFVALID,
			ID_M_OPTINSERTFIRST,
			ID_M_OPTINSERTDIFERENT,
			ID_M_NBLICENSE,
			ID_M_CHKSTARTUP,
			ID_M_CHKHIDDENMODE,
			ID_M_CHKPASSUNLOCK,
            ID_M_LBLLANGUAGE,
            ID_M_CBOLANGUAGE,
			ID_M_NBGENERAL,
			ID_M_TREEOPTIONS,
			ID_WXPANEL1,
			ID_WXPANELZ,

			ID_M_OPTPERSONALOFICIAL,
			ID_M_OPTOFICIALPERSONAL,
			ID_M_BOXLOADORDER,
			ID_M_EDTSERVER2CHECKLICENSE,
			ID_M_CHKAUTOUPDATE,
			ID_M_BOXSERVER2CHECKLICENSE,
			ID_M_NBCHECKINGLICENSE,
			ID_M_LBLCHECK2,
			ID_M_SPINLIC2CHECKINEVERYSERVER,
			ID_M_LBLLICENSESINEVERYSERVER,

			ID_M_LBLLICENSESATTHETIME,
			ID_M_SPINLICENSES2CHECK,
			ID_M_LBLCHECK,
            ID_M_AVOIDNEAREXPIRATION,

            ID_M_NBSERVERS,


			////GUI Enum Control ID End
            ID_ITEM_VISITSITE,
            ID_ITEM_COPY2CLIPBOARD,

            ID_ITEM_MODIFY,
            ID_ITEM_DELETE,
            ID_ITEM_ADDUSERTAG,
            ID_ITEM_ADDPASSTAG,
            ID_ITEM_ADDSERVERATFIRST,
            ID_ITEM_ADDSERVERATLAST,
            ID_ITEM_ADDSERVERBEFORESEL,
            ID_ITEM_ADDSERVERAFTERSEL,
            ID_ITEM_MOVEUP,
            ID_ITEM_MOVEDOWN,

			ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
		};
		
	private:
		void OnClose(wxCloseEvent& event);
		void CreateGUIControls();
};

#endif